package sopt.dev.network;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;

import com.google.gson.JsonObject;

public class LoginRequest extends NetworkRequest {
	private final String SERVER_IP = "http://163.239.200.121:8080";
	private HttpURLConnection conn;
	private JsonObject sendObj;

	public LoginRequest(String id, String pw) {
		
		sendObj = new JsonObject();
		sendObj.addProperty("user_id", id);
		sendObj.addProperty("user_pw", pw);
		 
		setUrl(SERVER_IP);
	}

	@Override
	public void parsing() {
		try {
			conn = (HttpURLConnection) url.openConnection();
			conn.setDoOutput(true);
			conn.setRequestMethod("POST");	
			conn.setRequestProperty("Content-Type", "application/json");

			// Create the form content
			OutputStream os = conn.getOutputStream();
			os.write(sendObj.toString().getBytes("UTF-8"));
			os.flush();
			os.close();

			// Buffer the result into a string
			BufferedReader br = new BufferedReader(new InputStreamReader(
					(conn.getInputStream())));
			StringBuilder sb = new StringBuilder();
			String line;
			while ((line = br.readLine()) != null) {
				sb.append(line);
			}
			br.close();

			conn.disconnect();
			
			result = sb.toString();
			
			//return sb.toString();
		} catch (IOException e) {
		}
		 
	}

}
